
import 'transaction.dart';


/// 分类模型
class Category {
  final String id;
  final String name;
  final String icon;
  final TransactionType type;
  final bool isDefault;
  final int sortOrder;

  Category({
    required this.id,
    required this.name,
    required this.icon,
    required this.type,
    this.isDefault = false,
    required this.sortOrder,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'name': name,
      'icon': icon,
      'type': type.name,
      'is_default': isDefault ? 1 : 0,
      'sort_order': sortOrder,
    };
  }

  factory Category.fromMap(Map<String, dynamic> map) {
    return Category(
      id: map['id'],
      name: map['name'],
      icon: map['icon'],
      type: TransactionType.values.firstWhere(
        (e) => e.name == map['type'],
      ),
      isDefault: map['is_default'] == 1,
      sortOrder: map['sort_order'],
    );
  }

  Category copyWith({
    String? name,
    String? icon,
    TransactionType? type,
    bool? isDefault,
    int? sortOrder,
  }) {
    return Category(
      id: id,
      name: name ?? this.name,
      icon: icon ?? this.icon,
      type: type ?? this.type,
      isDefault: isDefault ?? this.isDefault,
      sortOrder: sortOrder ?? this.sortOrder,
    );
  }
} 